using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.InventoryDataInterf;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class DiagnosticsItemController : Controller
    {
		private readonly IItemTypeRepository itemtypeRepository;
		private readonly IItemGroupRepository itemgroupRepository;
		private readonly IManufacturerRepository manufacturerRepository;
		private readonly IItemPictureRepository itempictureRepository;
		private readonly IItemStatusRepository itemstatusRepository;
		private readonly IDiagnosticItemRepository diagnosticsitemRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DiagnosticsItemController() //: this(new ItemTypeRepository(), new ItemGroupRepository(), new ManufacturerRepository(), new ItemPictureRepository(), new ItemStatusRepository(), new DiagnosticsItemRepository())
        {
            itemtypeRepository = Registry.RepositoryFactory.GetItemTypeRepository();
            this.itemgroupRepository = Registry.RepositoryFactory.GetItemGroupRepository();
            this.manufacturerRepository = Registry.RepositoryFactory.GetManufacturerRepository();
            this.itempictureRepository = Registry.RepositoryFactory.GetItemPictureRepository();
            this.itemstatusRepository = Registry.RepositoryFactory.GetItemStatusRepository();
            this.diagnosticsitemRepository = Registry.RepositoryFactory.GetDiagnosticItemRepository();
        }

        public DiagnosticsItemController(IItemTypeRepository itemtypeRepository, IItemGroupRepository itemgroupRepository, IManufacturerRepository manufacturerRepository, IItemPictureRepository itempictureRepository, IItemStatusRepository itemstatusRepository, IDiagnosticItemRepository diagnosticsitemRepository)
        {
			this.itemtypeRepository = itemtypeRepository;
			this.itemgroupRepository = itemgroupRepository;
			this.manufacturerRepository = manufacturerRepository;
			this.itempictureRepository = itempictureRepository;
			this.itemstatusRepository = itemstatusRepository;
			this.diagnosticsitemRepository = diagnosticsitemRepository;
        }

        //
        // GET: /DiagnosticsItem/

        public ViewResult Index()
        {
            return View(diagnosticsitemRepository.All);//Including(diagnosticsitem => diagnosticsitem.ItemType, diagnosticsitem => diagnosticsitem.Manufacturer, diagnosticsitem => diagnosticsitem.Picture, diagnosticsitem => diagnosticsitem.Prices, diagnosticsitem => diagnosticsitem.Diagnostics));
        }

        //
        // GET: /DiagnosticsItem/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(diagnosticsitemRepository.Find(id));
        }

        //
        // GET: /DiagnosticsItem/Create

        public ActionResult Create()
        {
			ViewBag.PossibleItemTypes = itemtypeRepository.All;
			ViewBag.PossibleItemGroups = itemgroupRepository.All;
			ViewBag.PossibleManufacturers = manufacturerRepository.All;
			ViewBag.PossiblePictures = itempictureRepository.All;
			ViewBag.PossibleItemStatus = itemstatusRepository.All;
            return View();
        } 

        //
        // POST: /DiagnosticsItem/Create

        [HttpPost]
        public ActionResult Create(DiagnosticsItem diagnosticsitem)
        {
            if (ModelState.IsValid) {
                diagnosticsitemRepository.InsertOrUpdate(diagnosticsitem);
                diagnosticsitemRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleItemTypes = itemtypeRepository.All;
				ViewBag.PossibleItemGroups = itemgroupRepository.All;
				ViewBag.PossibleManufacturers = manufacturerRepository.All;
				ViewBag.PossiblePictures = itempictureRepository.All;
				ViewBag.PossibleItemStatus = itemstatusRepository.All;
				return View();
			}
        }
        
        //
        // GET: /DiagnosticsItem/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleItemTypes = itemtypeRepository.All;
			ViewBag.PossibleItemGroups = itemgroupRepository.All;
			ViewBag.PossibleManufacturers = manufacturerRepository.All;
			ViewBag.PossiblePictures = itempictureRepository.All;
			ViewBag.PossibleItemStatus = itemstatusRepository.All;
             return View(diagnosticsitemRepository.Find(id));
        }

        //
        // POST: /DiagnosticsItem/Edit/5

        [HttpPost]
        public ActionResult Edit(DiagnosticsItem diagnosticsitem)
        {
            if (ModelState.IsValid) {
                diagnosticsitemRepository.InsertOrUpdate(diagnosticsitem);
                diagnosticsitemRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleItemTypes = itemtypeRepository.All;
				ViewBag.PossibleItemGroups = itemgroupRepository.All;
				ViewBag.PossibleManufacturers = manufacturerRepository.All;
				ViewBag.PossiblePictures = itempictureRepository.All;
				ViewBag.PossibleItemStatus = itemstatusRepository.All;
				return View();
			}
        }

        //
        // GET: /DiagnosticsItem/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(diagnosticsitemRepository.Find(id));
        }

        //
        // POST: /DiagnosticsItem/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var d = diagnosticsitemRepository.Find(id);
            diagnosticsitemRepository.Delete(d);
            diagnosticsitemRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

